package com.bearingnavi.android.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

import com.bearingnavi.android.R;
import com.bearingnavi.android.util.Preferences;

public class AboutDialog extends Dialog {

	private Context context;

	public AboutDialog(Context context) {
		
		super(context);
		this.context = context;
		
	}
	
	@Override
	public void onBackPressed() {
	}
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.about);
		
		Button website = (Button) findViewById(R.id.website);
		Button feedback = (Button) findViewById(R.id.feedback);
		Button confirm = (Button) findViewById(R.id.confirmAbout);

		
		final CheckBox checkBox = (CheckBox) findViewById(R.id.send_log_info);
		checkBox.setChecked(Preferences.getInstance().getSendLog());
		
		
		confirm.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				Preferences.getInstance().setSendLog(checkBox.isChecked());
				AboutDialog.this.dismiss();
			}
		});
		
		
		website.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				
				Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://code.google.com/p/bearing-navi"));
				context.startActivity(browse);
				
			}
		});
		

		feedback.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				Intent i = new Intent(Intent.ACTION_SEND);
				i.setType("text/plain");
				i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"aviv.avb@gmail.com", "liav.he@gmail.com"});
				i.putExtra(Intent.EXTRA_SUBJECT, "Bearing Navigation Feeadback");
				//i.putExtra(Intent.EXTRA_TEXT   , "body of email");
				try {
				    context.startActivity(Intent.createChooser(i, "Send email in:"));
				} catch (android.content.ActivityNotFoundException ex) {
					Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
				}

			}
		});
		
	}
	

}
